package training_camp.day6.leetcode454;

import java.util.HashMap;

class Solution {
    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        HashMap<Integer, Integer> map = new HashMap<>();
        int n1 = nums1.length;
        int n2 = nums2.length;
        int n3 = nums3.length;
        int n4 = nums4.length;
        for (int i = 0; i < n1; i++) {
            for (int j = 0; j < n2; j++) {
                map.put(-1 * (nums1[i] + nums2[j]), map.getOrDefault(-1 * (nums1[i] + nums2[j]), 0) + 1);
            }
        }
        int ans = 0;
        for (int i = 0; i < n3; i++) {
            for (int j = 0; j < n4; j++) {
                if (map.containsKey(nums3[i] + nums4[j])) {
                    ans += map.get(nums3[i]+nums4[j]);
                }
            }
        }
        return ans ;
    }
}